#include <d3d9.h>
#include <d3dx9.h>
#include "Face.h"
#include "Game.h"
#include "Textures.h"

Minicraft::Face::Face(D3DXMATRIX transformMatrix)
{
	this->transformationMatrix = transformMatrix;
	this->visible = true;
	this->texture = Minicraft::Textures::TextureList::dirt;
}

// Deconstructor
Minicraft::Face::~Face(){}

// Renders the face
void Minicraft::Face::Draw()
{
	if(visible) // If render is true
	{
		LPDIRECT3DDEVICE9 device = Minicraft::BufferCollectionInstance->GetD3DDevice();

		// select the vertex and index buffers to use
		device->SetStreamSource(0, Minicraft::BufferCollectionInstance->GetVertexBuffer(), 0, sizeof(CUSTOMVERTEX));
		device->SetIndices(Minicraft::BufferCollectionInstance->GetIndexBuffer());

		// set the world transformation
		device->SetTransform(D3DTS_WORLD, &(this->transformationMatrix));

		device->SetTexture(0, Minicraft::Textures::GetTextureByEnum( this->texture ));

		// draw the face
		device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2); 
	}
}

// Gets whether or not this object will render.
bool Minicraft::Face::GetVisible()
{
	return this->visible;
}

// Sets whether or not this object will render.
void Minicraft::Face::SetVisible(bool visible)
{
	this->visible = visible;
}

void Minicraft::Face::SetTexture(Minicraft::Textures::TextureList::e texture)
{
	this->texture = texture;
}